package cn.rui.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.rui.common.ResponseBean;
import cn.rui.pojo.exam.Paper;
import cn.rui.pojo.vo.PageVo;
import cn.rui.service.exam.PaperService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author 徽州大都督
 * @date 2021/6/25
 */
@RestController
@RequestMapping("paper")
@Api(tags = "试卷模块")
@Slf4j
public class PaperController {

    @Autowired
    private PaperService paperService;

    @PostMapping("allPaper/findPage")
    @SaCheckLogin
    @ApiOperation(value = "分页查询随机试卷列表")
    public ResponseBean randomPaperFindPage(@RequestBody PageVo pageVo, HttpSession session) {
        return paperService.randomPaperFindPage (pageVo, session);
    }

    @PostMapping("allPaperList/findPage")
    @SaCheckLogin
    @ApiOperation(value = "分页查询在线考试试卷列表")
    public ResponseBean randomPaperListFindPage(@RequestBody PageVo pageVo, HttpSession session) {
        return paperService.randomPaperListFindPage (pageVo, session);
    }

    @PostMapping("randomPaper/add")
    @SaCheckLogin
    @ApiOperation(value = "添加随机试卷")
    public ResponseBean randomPaperAdd(@RequestBody Paper paper, HttpSession session) {
        return paperService.randomPaperAdd (paper, session);
    }

    @PutMapping("randomPaper/updateStatus/{id}")
    @SaCheckLogin
    @ApiOperation(value = "改变随机试卷状态")
    public ResponseBean randomPaperUpdateStatus(@PathVariable("id")Long id) {
        return paperService.randomPaperUpdateStatus (id);
    }

    @PostMapping("manual/add/{checkList}")
    @SaCheckLogin
    @ApiOperation(value = "添加手动试卷")
    public ResponseBean manualAdd(@RequestBody Paper paper, @PathVariable("checkList") List<Long> checkList, HttpSession session) {
        return paperService.manualAdd (paper, checkList,session);
    }

    @GetMapping("random/findPaperById/{id}")
    @SaCheckLogin
    @ApiOperation(value = "生成随机试卷")
    public ResponseBean randomFindPaperById(@PathVariable("id")Long paperId, HttpSession session) {
        return paperService.randomFindPaperById (paperId,session);
    }

    @PostMapping("/userTestList")
    @SaCheckLogin
    @ApiOperation(value = "查询个人考试信息列表")
    public ResponseBean userTestList(@RequestBody PageVo pageVo, HttpSession session) {
        return paperService.userTestList (pageVo,session);
    }
}
